import java.util.Arrays;

public class MyStack {
    private int[] elem;
    private int usedSize;

    public MyStack() {
        this.elem = new int[10];
        usedSize = 0;
    }
    public void push(int val){
        if (isFull()){
            elem = Arrays.copyOf(elem,elem.length + (elem.length>>1));
        }
        elem[usedSize++] = val;
    }
    public boolean isFull(){
        if (usedSize == elem.length){
            return true;
        }
        return false;
    }

    public int pop(){
        if (isEmpty()){
            throw new RuntimeException("栈为空！");
        }
        return elem[--usedSize];
    }

    public int peek(){
        if (isEmpty()){
            throw new RuntimeException("栈为空！");
        }
        return elem[usedSize-1];
    }

    public boolean isEmpty(){
        return usedSize == 0;
    }
}
